/**
 * 12.整数转罗马数字
 */
public class Exerciser1 {
    int[] values = {1000,900,500,400,100,90,50,40,10,9,5,4,1};
    String[] roman = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"};
    public String intToRoman(int num) {
        StringBuffer ret = new StringBuffer();
        for(int i = 0;i < values.length;i++) {
            int x = values[i];
            String r = roman[i];
            while(num >= x) {
                // 把这一位(千、百、十、个)的所有数进行减法，把对应的roman值进行添加到ret中
                num -= x;
                ret.append(r);
            }
            if(num <= 0) {
                break;
            }
        }
        return ret.toString();
    }
}
